package com.momo.web.controller.sysSetting;

import com.momo.common.common.JSONResult;
import com.momo.common.req.sysSetting.authority.AclReq;
import com.momo.service.sysSetting.SysAclService;
import com.momo.web.controller.BaseController;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.validation.annotation.Validated;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestMethod;
import org.springframework.web.bind.annotation.RestController;

import java.io.UnsupportedEncodingException;

/**
 * Created by MOMO on 2019/3/21.
 * 权限点
 */
@RestController
@RequestMapping(value = "/platform/acl", method = RequestMethod.POST, produces = "application/json;charset=UTF-8")
@Slf4j
public class SysAclController extends BaseController {
    @Autowired
    private SysAclService sysAclService;

    @RequestMapping("/add/v1")
    public JSONResult add(@Validated(AclReq.Add.class) @RequestBody AclReq aclReq) {
        try {
            return sysAclService.add(aclReq, redisUser());
        } catch (UnsupportedEncodingException e) {
            log.error("新增权限点失败:{}", e.getMessage());
            return JSONResult.errorMap("新增权限点失败");
        }
    }

    @RequestMapping("/modify/v1")
    public JSONResult modify(@Validated(AclReq.Modify.class) @RequestBody AclReq aclReq) {
        try {
            return sysAclService.modify(aclReq, redisUser());
        } catch (UnsupportedEncodingException e) {
            log.error("编辑权限点失败:{}", e.getMessage());
            return JSONResult.errorMap("编辑权限点失败");
        }
    }
    @RequestMapping("/status/v1")
    public JSONResult status(@Validated(AclReq.Status.class) @RequestBody AclReq aclReq) {
        try {
            return sysAclService.status(aclReq, redisUser());
        } catch (UnsupportedEncodingException e) {
            log.error("编辑权限点状态失败:{}", e.getMessage());
            return JSONResult.errorMap("编辑权限点状态失败");
        }
    }
}
